/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
  <file> cpp_hello.cpp </file>
  <brief>
    testing the ULS-API in C++.
    This file is part of ULS, Unified Lexical Scheme.
  </brief>
  <author>
    Stanley J. Hong <babel96@gmail.com>, 2011.
  </author>
*/

#include "SampleLex.h"
#include "UlsStream.h"
#include <locale.h>

#include <iostream>
using namespace std;
using namespace ULS;
using namespace AAA::BBB;

void
test_basic(SampleLex *sam_lex)
{
	sam_lex->setLine("C++ hello world\n\t\n", -1, 0);

	while (sam_lex->getToken() != SampleLex::EOI) {
		sam_lex->printTok();
	}
}

void
test_input_file(SampleLex *sam_lex, string filename)
{
	sam_lex->printf("Welcome to ULS World!\n");
	sam_lex->printf("Testing ULS in C++, ...\n");

	sam_lex->pushFile(filename, 0);

	while (sam_lex->getToken() != SampleLex::EOI) {
		sam_lex->printf("\ttokstr:%k, tokid:%d, file-coord:%w\n", sam_lex->TokenId);
	}
}

void
test_streaming(SampleLex& sam_lex)
{
	string output_file = string("output1.uls");

	UlsStream *afile = new UlsStream(sam_lex);

	bool bStrFileReady = afile->createStream(output_file);

	string input_file = string("input1.txt");
	afile->startStream(input_file);

	afile->closeStream();

	delete afile;
}

int
main(int argc, char* argv[])
{
	SampleLex *sample_lex;
	string config_name = "sample.ulc";

	sample_lex = new SampleLex(config_name);

	if (argc < 2) {
		test_basic(sample_lex);
	} else {
		test_input_file(sample_lex, string(argv[1]));
	}

	delete sample_lex;

	return 0;
}

